(function($){

$(function(){
	$('.top-cart').mouseenter(function(){
		$('.shopping-cart').addClass('cart-hover')
		$('.top-car-list').stop(true).eq($('.shopping-cart').index(this)).animate({height:83,paddingTop:15})
	});
	$('.top-cart').mouseleave(function(){
		$('.shopping-cart').removeClass('cart-hover')
		$('.top-car-list').stop().eq($('.shopping-cart').index(this)).animate({height:0,paddingTop:0})
	})
	
	/////////////////////////////////////////////
	//nav
	$('.nav .n1 ').mouseover(function(){
//		console.log($('this').index()+'----')
//		console.log($('.nav .n1 ').index(this))
		$('.nav1 ').stop(true).animate({height:229},400);
		$('.nav-content ').stop(true).animate({height:234},400).addClass('nav-content-wrap');
		$('.nav1').css({display:'none'})
		
		$('.nav1').eq($('.nav .n1 ').index(this)).css({display:'block'})
		
	})
	
	$('.nav1 ').mouseover(function(){
		
		$('.nav1 ').stop(true).animate({height:229},400);
		$('.nav-content ').stop(true).animate({height:234},400).addClass('nav-content-wrap');
		$('.nav1').css({display:'none'})
		$('.nav1').eq($('.nav1').index(this)).css({display:'block'})
		
	})
	
	$('.nav .n1 ').mouseout(function(){
		
		$('.nav1 ').stop(true).animate({height:0},500 );
			
		$(".nav-content").stop(true).animate({height:0},500).removeClass('nav-content-wrap');
		
	})
	
	$('.nav1 ').mouseout(function(){
		
		$('.nav1 ').stop(true).animate({height:0},500);
		$(".nav-content").stop(true).animate({height:0},500).removeClass('nav-content-wrap');
			
	})
	////////////////////////////////////////////////////
	var 
		 oSearchBox     = $('.hearder-search'),
		 oSearch = $('.search'),
		 oSearchInput = $('.ipt'),
		 oBtn			= $('.btn'),
		 oSearchNotice  = $('.search-txt'),
		 oSearchList    = $('.search-list'),
		 iSearchIndex    = -1,
		 sOriHtml 	    = oSearchList.html();
		
	oSearch.hover(function(){
		 oSearch.addClass('border-over')
		 oBtn.addClass('border-over')
		
	},function(){
		 oSearch.removeClass('border-over')
		 oBtn.removeClass('border-over')
	})
	  oSearchInput.focus(function(){
		  oSearch.addClass('border-focus');
		  oBtn.addClass('border-focus');
		  oSearchNotice.fadeOut('fast');
		  oSearchList.css('display','block');
		  
	}).blur(function(){
		  oSearch.removeClass('border-focus');
		  oBtn.removeClass('border-focus');
		  oSearchList.css('display','none');
		  oSearchNotice.fadeIn('fast');
	}).keyup(function(ev){
		var 
			ev = ev || window.event,
			aLi=$('.search-list li');
		if(ev.keyCode===38 || ev.keyCode ===40){
			if(ev.keyCode ===38 && iSearchIndex >0){
				iSearchIndex--;
			}else if (ev.keyCode ===40 && iSearchIndex< aLi.length-1){
				iSearchIndex++;
			}
			//console.log(ev.keyCode+" -- "+iSearchIndex)
			 oSearchInput.val(aLi.removeClass('search-active').eq(iSearchIndex).addClass('search-active').data('key'));
		}
	}).bind('input propertychange',function(){
			var sSearchCon = $(this).val();
			if(sSearchCon) {
				$.ajax({
					url:'http://search.mi.com/search/expand',
					data: {keyword: sSearchCon},
					jsonp: 'jsonpcallback',
					dataType: 'jsonp',
					
					success:function(data){
						var sHtml="";
						data.forEach(function(v){
							sHtml +='<li data-key="'+v.Key+ '"><a href=javascript:;><span>约有'+v.Rst+'件</span>'+v.Key+'</a></li>';
						});
						if(sHtml){
							oSearchList.css('display','block').html(sHtml);
						}else{
							oSearchList.css('display','block');
						}
						iSearchIndex = -1
					}
				})
			}else{
				oSearchList.html(sOriHtml);
				iSearchIndex=-1;
			}
		})
	
	////////////////////////////////////////////////////
	//switchCard
	$('.list li').mouseover(function(){
		$(' .list li').removeClass('mouse_over_style');
		$('.list  li').eq($(' .list li').index(this)).addClass('mouse_over_style');
		$('.box_list').css('display','none');
		$('.box_list').eq($(' .list li').index(this)).css('display','block');
		
	});
	$('.list li').mouseout(function(){
		$('li').eq($('.list li').index(this)).removeClass('mouse_over_style');
		$('.box_list').eq($('.list li').index(this)).css('display','none');
	});
	$('.box_list').mouseover(function(){
		$('.box_list').eq($('.box_list').index(this)).css('display','block');
		$('.list li').eq($('.box_list').index(this)).addClass('mouse_over_style');
	});
	$('.bgbox').mouseout(function(){
		$('.list li').removeClass('mouse_over_style');
		$('.box_list').css('display','none');
	});
		
		
	///////////////////////////////////////////////////////	
	//轮播图
	var iCurrent=0,
		timer=null;
	//移入移出	
	$('banner-wrap').hover(function(){
		console.log('ads')
		clearInterval(timer);
		
	},function(){
		autoMove()
	})
	//往左运动
	$('.left-btn').click(function(){
		iCurrent--;
		//console.log(iCurrent+"l")
		move();
		
	})
	//往右运动
	$('.right-btn').click(function(){
		
		iCurrent++;
		//console.log(iCurrent+"r")
		move();
		
	})
	//自动运动
	autoMove()
	function autoMove(){
		timer=setInterval(function(){
			iCurrent++
			move()
			//console.log(iCurrent)
		},3000)
	}
	//划过pic-list
	$('.pic-list ').on('click','li',function(){
		var iIndex=$(this).index();
		//console.log(this)
		if(iIndex===iCurrent){
			return;
		}
		iCurrent=iIndex;
		move()
	})
	function move(){
		//console.log("--ii-"+iCurrent)
		//console.log("----"+$('.pic-list li').length)
		if(iCurrent>=$('.pic-list li').length){
			iCurrent=0;
		}
		if(iCurrent<0){
			iCurrent=$('.pic-list li').length-1;
		}
		
		$('.pic-box li').stop(true).animate({
			opacity:0
		},500,function(){
			$(this).css('display','none')
		})
		.eq(iCurrent).css('display','block').stop(true).animate({opacity:1})
		
		$('.pic-list li').removeClass('over').eq(iCurrent).addClass('over')
		
	}
	
	
	
});		
		
})(jQuery)